<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>toRef-基础用法</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <div id="Application">
    <div>姓名--state.name：{{state.name}}</div>
    <div>姓名2--nameRef：{{nameRef}}</div>
    <div>年龄：{{state.age}}</div>
  </div>
  <script>
    const App = Vue.createApp({
      setup() {
        // 响应式对象
        const state = Vue.reactive({
          name: "太凉",
          age: 18,
        });

        // 通过toRef创建一个Ref响应式
        const nameRef = Vue.toRef(state, "name");

        // 过3秒后改变 两者 保持引用关系
        setTimeout(() => {
          // update1:改变name属性
          state.name = "冰箱太凉";
        }, 3000);

        // 过6秒后改变 两者 保持引用关系
        setTimeout(() => {
          // update1:改变name属性
          nameRef.value = "我就是冰箱太凉";
        }, 6000);

        return {
          nameRef,
          state,
        };
      },
    });
    App.mount("#Application");
  </script>
</body>

</html>